#!/usr/bin/env python
# -*- coding:utf-8 -*-

from flask_restful import Resource, reqparse
from flask import jsonify , request,g

from service.userWordTimesService import UserWordTimesService
from controller.userWordTimesController import UserWordTimesController
from utils import commons
from utils.response_code import RET


class UserWordTimesOtherResource(Resource):

    @classmethod
    def sensitive_update(cls, user_word_id):
        if not user_word_id:
            return jsonify(code=RET.NODATA, message='primary key missed', error='primary key missed')

        parser = reqparse.RequestParser()
        parser.add_argument('is_delete', location='form', required=False, help='is_delete参数类型不正确或缺失')
        
        kwargs = parser.parse_args()
        kwargs = commons.put_remove_none(**kwargs)
        kwargs['user_word_id'] = user_word_id

        res = UserWordTimesController.update(**kwargs)

        return jsonify(code=res['code'], message=res['message'], data=res['data'])

    @classmethod
    def get_user_learning_records(cls):
        """
        获取指定用户的单词学习记录
        :return: JSON响应
        """
        user_id = g.user.get('user_id')
        if not user_id:
            return jsonify(code=RET.NODATA, message='user_id not found in g.user', data=None)
        response = UserWordTimesService.get_user_learning_records(user_id)
        return jsonify(response)